

import com.apstex.ifc2x3toolbox.ifc2x3.*;
import com.apstex.ifc2x3toolbox.ifcmodel.IfcModel;
import com.apstex.ifc2x3toolbox.ifcmodel.IfcModelListener;
import com.apstex.step.core.ClassInterface;
import com.apstex.step.core.STRING;
import com.apstex.step.header.File_Description;
import com.apstex.step.header.File_Name;
import com.apstex.step.header.File_Schema;

import javax.swing.tree.DefaultMutableTreeNode;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;

public class Reading {
    public static void main(String[] args) throws Exception {
        IfcModel ifcModel = new IfcModel();
        File stepFile = new File("项目1.ifc");
        ifcModel.readStepFile(stepFile);
        //URL stepURL = new URL("http://www.myifchomepage.com/myifcstepfile");
        //ifcModel.readStepFile(stepURL);
        //InputStream stepStream = myDBconnection.getStepFile("1234");
        //ifcModel.readStepFile(stepStream);
//        DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode("no model loaded");
//        Enumeration<?> enumeration;
//        enumeration=rootTreeNode.depthFirstEnumeration();//以深度遍历节点
//        while(enumeration.hasMoreElements()){
//            //遍历枚举对象.
//            //先定义一个节点变量.
//            DefaultMutableTreeNode node;
//            node=(DefaultMutableTreeNode) enumeration.nextElement();//将节点名称给node.
//            //根据级别输出占位符.
//            for(int l=0;l<node.getLevel();l++){
//                System.out.print("---");
//            }
//            System.out.println(node.getUserObject()+"       "+node.getUserObject().getClass().getName()+"    "+node.getUserObject().getClass().getSimpleName());//输入节点标签.
//            System.out.println(node.getUserObject());
//        }
        IfcProject ifcProject = ifcModel.getIfcProject();
        //get all IfcWall instances contained in the model
        //System.out.println();;
//        Collection<IfcWallType> wallTypes = ifcModel.getCollection(IfcWallType.class);
//        for (IfcWallType wallType: wallTypes){
//            IfcWallType ifcWallType = wallType;
//            System.out.println(ifcWallType.getOwnerHistory().getOwningUser().getThePerson().getGivenName());
//        }
        Collection<IfcWall> walls = ifcModel.getCollection(IfcWall.class);
        System.out.println(walls.size());
        for (IfcWall wall: walls){
            System.out.println(wall.getObjectType());
//            IfcWall ifcWall = wall;
//            IfcProductRepresentation representation = ifcWall.getRepresentation();
//            IfcProductRepresentation newRep = new IfcProductRepresentation();
//            newRep.setName(new IfcLabel(String.valueOf(new STRING("myRepresentation",true))));
//            ifcWall.setRepresentation(newRep);
//            System.out.println(ifcWall);
            //System.out.println(ifcWall.getRepresentation().getName());
        }
       //get all IfcProduct instances contained in the model (includes all walls)
        Collection<IfcProduct> products = ifcModel.getCollection(IfcProduct.class);
        //System.out.println(products);
        IfcProductRepresentation representation = new IfcProductRepresentation();
        IfcRepresentation rep1 = new IfcRepresentation();
        representation.addRepresentations(rep1);
        //System.out.println(representation.getRepresentations());
        representation.removeRepresentations(rep1);
       // System.out.println(representation.getRepresentations());
        IfcWall ifcWall =new IfcWall();
        IfcProductRepresentation representation1 = ifcWall.getRepresentation();
        IfcProductRepresentation newRep = new IfcProductRepresentation();
        newRep.setName(new IfcLabel(String.valueOf(new STRING("myRepresentation",true))));
        ifcWall.setRepresentation(newRep);
        //System.out.println(ifcWall.getRepresentation().getDescription());
        //System.out.println(ifcWall.getRepresentation().getName());
        IfcQuantityArea ifcQuantityArea = new IfcQuantityArea();
        IfcAreaMeasure ifcAreaMeasure = ifcQuantityArea.getAreaValue();
        //IfcFaceBound ifcFaceBound =
        //boolean orientation = ifcFaceBound.getOrientation().value;
//        Collection<ClassInterface> newObjects = new ArrayList<>();
//        IfcWall wall1 = new IfcWall();
//        newObjects.add(wall1);
//        IfcWall wall2 = new IfcWall();
//        newObjects.add(wall2);
        //ifcModel.addIfcModelListener((IfcModelListener) newObjects);
        File_Description description = ifcModel.getFile_Description();
        //System.out.println(description);
        File_Name fileName = ifcModel.getFile_Name();
        STRING authorization = fileName.getauthorization();
        //System.out.println(authorization);
        STRING name = fileName.getname();
        //System.out.println(name);
        File_Schema schema = ifcModel.getFile_Schema();
    }
}
